package com.zhiy.com.estation.ui.fragment;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.zhiy.com.estation.R;
import com.zhiy.com.estation.model.User;
import com.zhiy.com.estation.ui.base.BaseFragment;
import com.zhiy.com.estation.ui.fragment.find.back.password.FindPassContract;
import com.zhiy.com.estation.ui.fragment.find.back.password.FindPassModel;
import com.zhiy.com.estation.ui.fragment.find.back.password.FindPassPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Zyh on 2016/12/4.
 */
public class Fragment_Find_Pass extends BaseFragment implements FindPassContract.View {
    @Override
    protected int getInflaterLayoutId() {
        return R.layout.fra_forg_pass;
    }
    @BindView(R.id.find_pass_et)
    EditText nameEt;
    @Override
    protected void initView(View view) {
        mTitleBar.setTitle("找回密码");

    }
    @OnClick(R.id.find_pass_bt)
    public void findPassClick(){
        String name=nameEt.getText().toString();
        if (TextUtils.isEmpty(name)){
            Toast.makeText(mContext, "查找用户名不能为空", Toast.LENGTH_SHORT).show();
        }else {
            FindPassPresenter presenter=new FindPassPresenter();
            presenter.setMV(new FindPassModel(),this);
            presenter.findPassword(name);
        }
    }
    @Override
    public void isSuccess(User user) {
        android.app.AlertDialog.Builder builder=new android.app.AlertDialog.Builder(mBaseActivity);
        builder.setTitle("请保管好你的密码：");
        String password=user.getPassword();
        builder.setMessage(password);
        builder.setCancelable(false);

        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                //这里的i代表确认按钮对应的值
                Log.d("---",i+"");
                dialogInterface.dismiss();
            }
        });
        builder.create().show();
    }

    @Override
    public void showMsg(String msg) {

    }

    @Override
    public void isFailure() {

    }
}
